package cn.phonevane.service.impl;

import java.util.List;

import cn.phonevane.dao.BaseDao;
import cn.phonevane.dao.UserDao;
import cn.phonevane.model.TUser;
import cn.phonevane.service.UserService;
/**
 * �û�����ʵ��
 * 
 * @author xuanaiwu
 */
public class UserServiceImpl implements UserService{
	
	private BaseDao baseDao;
	
	private UserDao userDao;
	
	public BaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * �������增加用户
	 * @param object 
	 * @return boolean
	 */

	public boolean add(Object object) {
		
		return baseDao.save(object);
	}
	
	/**
	 * �˶��û�用户登录
	 * @param  username
	 * @param  password
	 */
	public TUser check(String username,String password){
		List<TUser> tUserList=null;
		String hql="from TUser as u where u.userName=:userName and u.userPass=:userPass";
		tUserList=this.userDao.query(username, password, hql);
		if(tUserList!=null&&tUserList.size()>=1){
			return tUserList.get(0);
		}
		return null;
	}
	
	/**
	 * �˶��û�用户注册
	 * @param  username
	 */
	public boolean checkUsername(String username) {
		String hql="select u.userName from TUser as u where u.userName=:userName";
		List list=this.userDao.query(username, hql);
		
		if(list.size()>0){
			return true;
		}
		return false;
	}

}
